<template>
    <div>
        <el-row>
            <top-bar></top-bar>
        </el-row>
        <el-row>
            <el-col :span="4">
                <body-left></body-left>
            </el-col>
            <el-col :span="20">
                <router-view></router-view>
            </el-col>
        </el-row>
    </div>
</template>

<script>
    import topBar from '@/components/topbar.vue'
    import bodyLeft from '@/components/bodyLeft.vue'

    export default {
        data() {
            return {
            }
        },
        components: {
            topBar, bodyLeft
        },
        methods: {
            getToken() {
                return document.cookie.valueOf('token').substr(6, 32)
            },
            checkToken(token, func) {
                this.$axios.get(this.$api.API_LOGIN + '/' + token).then(res => {
                    if (res.status === 200 && res.data.status === 'true') {
                        func()
                    }
                }).catch(e => {
                    console.log(e)
                })
            }
        },
        mounted() {
            let token = this.getToken()
            if (token === 'undefined') {
                this.$router.push('/login')
            }
            this.checkToken(token, () => {
                this.$router.push('/home')
            })
        }
    }
</script>